Add explicit host_triple to BuildConfig
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 13 Jul 2016 16:38:10 +0000 (19:38 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 13 Jul 2016 17:53:57 +0000 (20:53 +0300)
src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/mod.rs

index 47aaaa00d3864f3486ffaa8ceee419a98c565642..b205593376fe8cda5c2a10849bd68de64bb880af 100644 (file)
@@ -35,8 +35,9 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
     let profiles = try!(ws.current()).manifest().profiles();
     let mut cx = try!(Context::new(ws, &resolve, &packages, opts.config,
                                    BuildConfig {
-                                       release: opts.release,
+                                       host_triple: opts.config.rustc_info().host.clone(),
                                        requested_target: opts.target.map(|s| s.to_owned()),
+                                       release: opts.release,
                                        ..BuildConfig::default()
                                    },
                                    profiles));
index 8f175324aabe43038be858d316c0c6467a314fc9..744cc54e9003547eb7020e7e9e842df7321f8e0c 100644 (file)
@@ -443,11 +443,12 @@ fn scrape_build_config(config: &Config,
     let cfg_target = try!(config.get_string("build.target")).map(|s| s.val);
     let target = target.or(cfg_target);
     let mut base = ops::BuildConfig {
-        jobs: jobs,
+        host_triple: config.rustc_info().host.clone(),
         requested_target: target.clone(),
+        jobs: jobs,
         ..Default::default()
     };
-    base.host = try!(scrape_target_config(config, &config.rustc_info().host));
+    base.host = try!(scrape_target_config(config, &base.host_triple));
     base.target = match target.as_ref() {
         Some(triple) => try!(scrape_target_config(config, &triple)),
         None => base.host.clone(),
index 53678eb5b1f0739177f2a6e51ad29488f139ee9f..0736d9fe68c889d9ad20f9b4c41fe95148a26f63 100644 (file)
@@ -42,7 +42,6 @@ pub struct Context<'a, 'cfg: 'a> {
 
     host: Layout,
     target: Option<Layout>,
-    target_triple: String,
     target_info: TargetInfo,
     host_info: TargetInfo,
     profiles: &'a Profiles,
@@ -71,16 +70,10 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             None => None,
         };
 
-        let target = build_config.requested_target.clone();
-        let target = target.as_ref().map(|s| &s[..]);
-        let target_triple = target.unwrap_or_else(|| {
-            &config.rustc_info().host[..]
-        }).to_string();
         let engine = build_config.exec_engine.as_ref().cloned().unwrap_or({
             Arc::new(Box::new(ProcessEngine))
         });
         Ok(Context {
-            target_triple: target_triple,
             host: host_layout,
             target: target_layout,
             resolve: resolve,
@@ -138,7 +131,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             try!(self.visit_crate_type(unit, &mut crate_types));
         }
         try!(self.probe_target_info_kind(&crate_types, Kind::Target));
-        if self.build_config.requested_target.is_none() {
+        if self.requested_target().is_none() {
             self.host_info = self.target_info.clone();
         } else {
             try!(self.probe_target_info_kind(&crate_types, Kind::Host));
@@ -184,7 +177,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             process.arg("--crate-type").arg(crate_type);
         }
         if kind == Kind::Target {
-            process.arg("--target").arg(&self.target_triple);
+            process.arg("--target").arg(&self.target_triple());
         }
 
         let mut with_cfg = process.clone();
@@ -266,12 +259,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
 
     /// Return the host triple for this context
     pub fn host_triple(&self) -> &str {
-        &self.config.rustc_info().host[..]
+        &self.build_config.host_triple
     }
 
     /// Return the target triple which this context is targeting.
     pub fn target_triple(&self) -> &str {
-        &self.target_triple
+        self.requested_target().unwrap_or(self.host_triple())
     }
 
     /// Requested (not actual) target for the build
@@ -376,11 +369,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             if unsupported.len() > 0 {
                 bail!("cannot produce {} for `{}` as the target `{}` \
                        does not support these crate types",
-                      unsupported.join(", "), unit.pkg, self.target_triple)
+                      unsupported.join(", "), unit.pkg, self.target_triple())
             }
             bail!("cannot compile `{}` as the target `{}` does not \
                    support any of the output crate types",
-                  unit.pkg, self.target_triple);
+                  unit.pkg, self.target_triple());
         }
         Ok(ret)
     }
index 3401145f4db8f08c6fcaf8142eb831b00bd18f8e..204d4d0adb3b6d2c7b1c2272a566c21451bc1238 100644 (file)
@@ -35,10 +35,11 @@ pub enum Kind { Host, Target }
 
 #[derive(Default, Clone)]
 pub struct BuildConfig {
+    pub host_triple: String,
     pub host: TargetConfig,
+    pub requested_target: Option<String>,
     pub target: TargetConfig,
     pub jobs: u32,
-    pub requested_target: Option<String>,
     pub exec_engine: Option<Arc<Box<ExecEngine>>>,
     pub release: bool,
     pub test: bool,